package entry;

import java.util.*;

public class Library {

    private Map<String,Integer> data = new HashMap<String, Integer>();
    private List<String> dataList = new ArrayList<String>();
    private String category;

    public void put(String word){
        Integer amount = data.put(word,1);
        if(amount!=null){
            data.put(word,amount+1);
        }else {
            dataList.add(word);
        }
    }

    public void put(String word,int count){
        Integer amount = data.put(word,count);
        if(amount!=null){
            data.put(word,amount+count);
        }else {
            dataList.add(word);
        }
    }

    public Integer getAmountByKey(String key){
        Integer amount = 0;
        for(Map.Entry<String,Integer> map : data.entrySet()) {
            if(key.equals(map.getKey())) {
                amount = map.getValue();
                break;
            }
        }
        return amount;
    }

    @Override
    public String toString() {
        return data.toString();
    }

    public int size(){
        return data.size();
    }

    public Iterator iterator(){
        return data.entrySet().iterator();
    }

    public void remove(String key){
        data.remove(key);
        dataList.remove(key);
    }

    public Map<String, Integer> getData() {
        return data;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public boolean isExist(String str){
        Integer integer = data.get(str);
        if(integer != null){
            return true;
        }else {
            return false;
        }
    }

    public List<String> getDataList(){
        List<String> dataList = new ArrayList<String>();
        for(Map.Entry<String,Integer> entry:data.entrySet()){
            dataList.add(entry.getKey());
        }
        return dataList;
    }
}

